// 检测两个矩形是否重叠的函数
const isOverlapping = (rect1, rect2) => {
    return !(
        rect1.x + rect1.width <= rect2.x ||
        rect2.x + rect2.width <= rect1.x ||
        rect1.y + rect1.height <= rect2.y ||
        rect2.y + rect2.height <= rect1.y
    );
  }
  // 生成随机位置的函数 
  const generateRandomPosition = (existingPositions, parentWidth, parentHeight, elementWidth, elementHeight) => {
    let position;
    let overlap;
   
    do {
      overlap = false;
      position = {
        x: Math.floor(Math.random() * (parentWidth - elementWidth)),
        y: Math.floor(Math.random() * (parentHeight - elementHeight)),
        width: elementWidth,
        height: elementHeight,
        transform: Math.floor(Math.random() * (angleRange + angleRange + 1)) - angleRange,
        text: ''
      };
   
      // 检查新位置是否与现有位置重叠
      for (const existing of existingPositions) {
        if (isOverlapping(position, existing)) {
          overlap = true;
          break;
        }
      }
    } while (overlap);
   
    return position;
  }
  const changeSelectImage = () => {
    const newPositions = [];  // 用来生成文字定位信息
    // （所需字符串的长度）    allTextNum：生成点击文字的个数
    let textOptionArr = getRandomUniqueIndexes(textString.length, allTextNum)
    let textSelectString = ''  // 生成的文本顺序
    for (let i = 0; i < allTextNum; i++) {
          // 位置信息     图片宽度    图片高度    文本宽度
      const newPosition = generateRandomPosition(newPositions, parentWidth, parentHeight, textWidth, textWidth);
      newPositions.push({...newPosition, text: textString[textOptionArr[i]]});
      textSelectString += textString[textOptionArr[i]]
    }
    textRank.value = textSelectString
    textPosition.textPositionData = newPositions
  }
   
   
   
   
   
   
  // 下面是一个函数进行随机数生成  第一个参数所需字符串长度   第二个参数需要生成的数量 这里只是复制进来的 改的话直接删除export就行了
  export const getRandomUniqueIndexes = (max, count) => {
      const indexes = [];
      while (indexes.length < count) {
          const randomIndex = Math.floor(Math.random() * max);
          if (!indexes.includes(randomIndex)) {
              indexes.push(randomIndex);
          }
      }
      return indexes;
  };